package com.lance.answer.question_answer.xj_new;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.lance.answer.dto.GkUser;
import com.lance.answer.dto.XjStudentCourseInfo;
import com.lance.answer.gui.answer.Util;
import com.lance.answer.gui.answer.gk.DealInfoUtil;
import com.lance.answer.gui.answer.gk.video.dto.WatchVideoDto;
import com.lance.answer.question_export.gk_new.GetGkCourseInfoTask;
import com.lance.answer.util.Constant;
import com.lance.answer.util.HttpUtil;
import com.lance.answer.util.XinJiangUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @author fengx
 * 获取新疆一体化 每个学生的课程信息  这个不是tmp 是真的有用的，多线程获取学生信息
 */
public class GetXjStudentCourseInfo {





    public static void main(String[] args) throws IOException {



        int sync = 12;
        //   String majorName = "tmp新生刷课1124";



        File file= new File("E:\\XjStudentCourseInfoTmp\\deal");

        List<String> names = Lists.newArrayList();
        for(File file1:file.listFiles()){

          //  if(file1.length()<1024){
            if(file1.length()<1){
                continue;
            }

            String file1Name = file1.getName();
            System.err.println(file1Name);
            names.add(file1Name.substring(0,file1Name.length()-5));
        }


        System.err.println("namesSize:"+names.size());


     //   InputStream inputStream3 = new FileInputStream("D:\\answers\\" + majorName + ".user");
     //   InputStream inputStream3 = new FileInputStream("E:\\一体化2022.user");
     //   InputStream inputStream3 = new FileInputStream("E:\\alluser.txt");
        InputStream inputStream3 = new FileInputStream("E:\\一体化补2022.txt");
        List<String> users = IOUtils.readLines(inputStream3, "utf-8");

        LinkedBlockingDeque<GkUser> usersQueue = new LinkedBlockingDeque<>();



        for(String username:users){
            String[] strs = username.split(",");
            String userCode = strs[0];

            System.err.println("strs:"+username);
            if(names.contains(userCode)){
                continue;
            }
//            if(!userCode.equals("653222199911203719")){
//                continue;
//            }

            String pwd = strs[1];
            if (pwd.length() > 14) {
                if (pwd.contains("X")||pwd.contains("x")) {
                    pwd = userCode.substring(11, 17);
                } else {
                    pwd = userCode.substring(12);
                }
            }


            GkUser gkUser = new GkUser();
            gkUser.setUsername(userCode);
            gkUser.setPwd(pwd);
            //   videoDto.setSubjectCode(subjectCode);

            usersQueue.add(gkUser);
        }


        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new GetXjStudentCourseInfoTask(null,usersQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName( "答题线程--" + i);
            answerThread.start();
        }



    }


    //   WebDriver driver = Util.getDriver("d:\\ynouAutoStudy\\chromedriver.exe");


}














